<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('防疫物资申请列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <input type="text" name="placeName" placeholder="核酸点名称"/>
                            </li>
                            <li>
                                <input type="text" name="teamName" placeholder="队伍名称"/>
                            </li>
                            <li>
                                <select name="applyStatus" th:with="type=${@dict.getType('fym_good_apply_status')}">
                                    <option value='' disabled selected style='display:none;'>审批节点</option>  
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <!-- <li>
                                <label>下一审批人：</label>
                                <input type="text" name="nextPerson"/>
                            </li>
                            <li>
                                <label>流水号：</label>
                                <input type="text" name="liushuiNumber"/>
                            </li> -->
                            <!-- <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li> -->
                            
                            <div class="btn-group-sm" id="toolbar2" role="group">
                            	<a class="btn btn-outline btn-success btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;精准搜索</a>
				                <!-- <a class="btn btn-outline btn-success btn-sm " onclick="$.operate.add()" shiro:hasPermission="fym:apply:add">
				                    <i class="fa fa-plus"></i> 精准添加
				                </a> -->
				                <!-- <a class="btn btn-white btn-sm multiple disabled" onclick="$.operate.edit()" shiro:hasPermission="fym:apply:edit">
				                    <i class="fa fa-edit"></i> 修改
				                </a> -->
				                <a class="btn btn-white btn-sm multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="fym:apply:remove">
				                    <i class="fa fa-remove"></i> 批量删除
				                </a>
				                <!-- <a class="btn btn-link btn-sm" onclick="$.table.exportExcel()" shiro:hasPermission="fym:apply:export">
				                    <i class="fa fa-upload"></i> 导入
				                </a> -->
				                <a class="btn btn-link btn-sm" onclick="$.table.exportExcel()" shiro:hasPermission="fym:apply:export">
				                    <i class="fa fa-download"></i> 导出
				                </a>
				            </div>
                        </ul>
                    </div>
                </form>
            </div>

            <!-- <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-outline btn-success btn-sm " onclick="$.operate.add()" shiro:hasPermission="fym:apply:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-white btn-sm multiple disabled" onclick="$.operate.edit()" shiro:hasPermission="fym:apply:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-white btn-sm multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="fym:apply:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-link btn-sm" onclick="$.table.exportExcel()" shiro:hasPermission="fym:apply:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div> -->
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('fym:apply:edit')}]];
        var removeFlag = [[${@permission.hasPermi('fym:apply:remove')}]];
        var applyStatusDatas = [[${@dict.getType('fym_good_apply_status')}]];
        var prefix = ctx + "fym/apply";

      function approval(applyId){
		$.modal.confirm("确认要点击审批吗?", function() {
			$.ajax({
				type: "post",
				url: prefix + "/approval",
				data: {
					"applyId": applyId
				},
				success: function(data) {
					console.log(data);
					if(data.code==0){
						location.reload();
					}else{
						$.modal.alert("审批失败!");
					}
				}
			});
			
		});
      }
	    
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                detailUrl: prefix + "/detail/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "防疫物资申请",
		        showSearch: false,
		        showRefresh: false,
		        showToggle: false,
		        showColumns: false,
                columns: [{
                    checkbox: true
                },
                {
                    field: 'applyId',
                    title: '主键',
                    visible: false
                },
               /*  {
                    field: 'placeId',
                    title: '核酸点ID'
                }, */
                {
                    field: 'placeName',
                    title: '核酸点名称'
                },
                /* {
                    field: 'teamId',
                    title: '队伍ID',
                }, */
                {
                    field: 'teamName',
                    title: '队伍名称'
                },
                {
                    field: 'applyStatus',
                    title: '审批节点',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(applyStatusDatas, value);
                    }
                },
                {
                    field: 'nextPerson',
                    title: '下一审批人'
                },
                {
                    field: 'goodsContent',
                    title: '具体物资内容'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    title: '照片',
                    field: 'receiveImg',
                   	formatter: function(value, row, index) {
   				    	// 图片预览（注意：如存储在本地直接获取数据库路径，如有配置context-path需要使用ctx+路径）
   				    	// 如：/profile/upload/2019/08/08/3b7a839aced67397bac694d77611ce72.png
   				    	if(!value){
   				    		return $.table.imageView(value);
   				    	}else{
   				    		//多个图片
   				    		if(value.indexOf(',') != -1){
   				    			var arr = value.split(",");
   				    			return $.table.imageViewMultiple(arr,ctx);
   				    		}
   				    		return $.table.imageView(ctx + value);
   				    	}
   				    }
                },
                /* {
                    field: 'liushuiNumber',
                    title: '流水号'
                }, */
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-link btn-xs blue' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.applyId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-link btn-xs red' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.applyId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        console.log(row);
                        if(row.applyStatus==4){
                        	actions.push('<a class="btn btn-link btn-xs disabled ' + removeFlag + '" href="javascript:void(0)" onclick="approval(\'' + row.applyId + '\')"><i class="fa fa-signing"></i>完结</a>');
                        }else if(row.applyStatus==3){
                        	actions.push('<a class="btn btn-link btn-xs disabled ' + removeFlag + '" href="javascript:void(0)" onclick="approval(\'' + row.applyId + '\')">待接收</a>');
                        }else if(row.applyStatus==2){
                        	//进行已受理审批的时候需要填写	人员、车辆及备注
                        	actions.push('<a class="btn btn-link btn-xs' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'--' + row.applyId + '\')"><i class="fa fa-hand-lizard-o"></i>调度</a> ');
                            
                        }else{
                        	actions.push('<a class="btn btn-link btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="approval(\'' + row.applyId + '\')"><i class="fa fa-paint-brush"></i>办理</a>');
                        }
                        
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>